<!DOCTYPE HTML>
<html>
<head>
<#include "head.html">
<link rel="stylesheet" type="text/css" href="${contextPath}/common/mask.css" />
<title>抖音视频</title>
</head>
<!-- 资源列表 -->
<body>
<nav class="breadcrumb" style="padding: 0px 15px;margin-bottom: 0px; "><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
    <#if pmenu.menuName!>
        ${(pmenu.menuName)!}
        <span class="c-gray en">&gt;</span>
    </#if>
    ${(menu.menuName)!}
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">
		<input type="text" class="input-text" style="width:250px" placeholder="输入名称" id="name" name="">
		<button type="button" class="btn btn-success" id="" onclick="App.seach()" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
	</div>
	<div class="mt-20">
		<span class="l">
			<@shiro.hasPermission name="EditDouyinVideo">
			<a href="javascript:;" onclick="App.add()" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加</a>
			</@shiro.hasPermission>
		</span>
	</div>
	<table id="table">
		<thead>
	        <tr>
	        	<th></th>
                <th>视频标题</th>
                <th>原链接</th>
                <th>服务器链接</th>
                <th>作者抖音id</th>
                <th>作者头像</th>
                <th>作者名称</th>
                <th>扩展信息（json数据）</th>
                <th>创建时间</th>
				<th>操作</th>
	        </tr>
	    </thead>
	</table>
</div>

<input type="hidden" value="${(staticUrl)!}" id="staticUrl">
<div class="hj-mask">
	<div style="width: 100%; color: #fff; padding-top:1rem; padding-left:1rem; background: rgba(0, 0, 0, 0.7);" onclick="returnHtml()"><i class="Hui-iconfont">&#xe67d;</i></div>
	<video width="100%" height="100%" src="" id="getVideo" controls="controls"> 
	</video>
</div>
</body>
<#include "footer.html">
<script type="text/javascript">
var staticUrl=$("#staticUrl").val();
$(function(){
// 	maskCenter();
    var bs_table=BootstrapTable.init({
        url:"${contextPath}/douyinVideo/list.do",
        data:{
        },
        columns:[
            {checkbox: true},
            {field: 'videoTitle'},
            {field: 'url'},
            {field: 'watermarkVideo'},
            {field: 'authorId'},
            {field: 'authorHeadImgUrl'},
            {field: 'authorName'},
            {field: 'extendInfo'},
            {field: 'createTime'},
            {align: 'center',
                formatter: function (value, row, index) {
                    var html='';
                    
                    
                html+='<a  href="javascript:;" onclick="preview(&quot;'+row.watermarkVideo+'&quot;)"  title="预览"><i class="Hui-iconfont">&#xe695;</i></a>'; 
                
                html+='<a  onclick="downloadFile(this,&quot;'+row.watermarkVideo+'&quot;,&quot;'+row.id+'&quot;)" id="downloadFile'+row.id+'"  title="下载"><i class="Hui-iconfont">&#xe640;</i></a>'; 
                
                //解析
                if(isNotEmpty(row.watermarkUrl)){
                	  html+='<a  onclick="App.analysis(this,&quot;'+row.url+'&quot;)" href="javascript:;" title="解析"><i class="Hui-iconfont">&#xe63c;</i></a>'; 
                }
                   
                <@shiro.hasPermission name="EditDouyinVideo">
					html+='<a title="编辑" href="javascript:;" onclick="App.edit(this,'+row.id+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>';
                </@shiro.hasPermission>
                
                <@shiro.hasPermission name="DelDouyinVideo">
                    html+='<a title="删除" href="javascript:;" onclick="App.del(this,'+row.id+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
                </@shiro.hasPermission>
					return html;
                }
            }

        ]
    })

App={
	seach: function (){
        var data={
            name:$("#name").val(),
        }
		bs_table.seach(data);
	},
	/*增加*/
	add:function (){
	    AppList.add("${contextPath}/douyinVideo/goEdit.do")
	},
	/*编辑*/
	edit:function (obj,id){
        AppList.edit("${contextPath}/douyinVideo/goEdit.do?id="+id)
	},
	/*删除*/
	del:function (obj,id){
	    var config={
	        url:'${contextPath}/douyinVideo/del.do',
            data:{
                id:id,
            },
			table:bs_table,
		}
        AppList.del(config)
	},
	/*停用*/
	stop:function (obj,id){
        var config={
            url:'${contextPath}/douyinVideo/update.do',
            data:{
                id:id,
                state:2
            },
            table:bs_table,
        }
        AppList.stop(config)
	},
	/*启用*/
	start:function (obj,id){
        var config={
            url:'${contextPath}/douyinVideo/update.do',
            data:{
                id:id,
                state:1
            },
            table:bs_table,
        }
        AppList.start(config)
	},
	analysis:function  (obj,url){
		layer.confirm('确认解析吗？',function(){
			$.ajax({
				type:"post",
				url:"${contextPath}/dy/api/analysisVideo.do",
				data:{url:url},
				success:function(data){
					if(data.msg=="success"){
                        layer.msg('解析成功',{icon:1,time:1000});
                    }else{
                        layer.alert(data.msg||"解析失败");
                    }
				},
				error:function(data) {
                    layer.alert(data.msg||"解析失败");
                }
			});
		});
	}
}
});

//遮罩层居中
function maskCenter(){
	var windowHeight=$(window).height();
	var height=$('.hj-mask-main').height();
	var centerHeight=(windowHeight-height)/2;
	$('.hj-mask-main').css('top',centerHeight);
}


$(".hj-mask").click(function(){
	$('.hj-mask').hide();
});

function returnHtml(){
	$('.hj-mask').hide();
}

function preview(obj){
	$('.hj-mask').show();
	obj=obj.replace("home","shareFolder");
	console.log("正在预览:"+obj);
	$("#getVideo").attr("src",+staticUrl+"/"+obj);
}

function downloadFile(obj,url,id){
	if(isEmpty(url)){
		 layer.alert("url为空，请重新解析");
		 return false;
	}
	url=url.replace("home","shareFolder");
	console.log(url);
// 	$("#downloadFile"+id).attr("href",'${contextPath}/dy/api/downloadFile?url=http://47.101.141.16:8083'+url);
// 	$("#downloadFile"+id).click();
	self.location.href='${contextPath}/dy/api/downloadFile?url='+staticUrl+url
}




</script>
</html>